Skip to content

Fix out-of-bounds bank_index read in MCPL empty-bank unit test - #4254

Open
kvnloo wants to merge 1 commit into
openmc-dev:developfrom
kvnloo:fix-mcpl-empty-bank-index
Open

kvnloo wants to merge 1 commit into
openmc-dev:developfrom
kvnloo:fix-mcpl-empty-bank-index

Conversation

@kvnloo

@kvnloo kvnloo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

The "stat:sum handles empty particle bank" section of test_mcpl_stat_sum passed bank_index = {0}. write_mcpl_source_bank_internal() expects n_procs + 1 cumulative offsets and reads bank_index_all_ranks[rank_idx + 1], so with one rank the test read past the end of a one-element vector. Plain builds happen to pass. A standard library with bounds checks traps on that read, which is the SIGILL in #4054 (FreeBSD's libc++ is hardened). This PR uses {0, 0}, the offsets for one rank holding no particles. It is a test-only change. Real callers already pass n_procs + 1 entries.

Reproduced on develop at 5d63501, Ubuntu 24.04, MCPL from pip install mcpl, running tests/cpp_unit_tests test_mcpl_stat_sum:

Build develop this PR
GCC 13, plain (what CI builds) passes (6 assertions) passes (6 assertions)
GCC 13, -D_GLIBCXX_ASSERTIONS SIGABRT at line 89, __n < this->size() (exit 134) passes
clang 18, -stdlib=libc++ -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST SIGILL at line 89, assertions: 6 | 5 passed | 1 failed (exit 132), the same as the report passes

With the fix, all 16 C++ unit tests also pass under -D_GLIBCXX_ASSERTIONS (ctest, 16/16). Removal control: reverting the one-line change in the same assertions build brings back the SIGABRT (exit 134). These runs were local builds (cmake -DOPENMC_FORCE_FETCHCONTENT=ON -DOPENMC_USE_OPENMP=OFF); the full CI matrix will run here on the PR.

Fixes #4054

AI Assistance

  • Harness: Hermes Agent (Claude Agent SDK)
  • Model: Claude Opus 5.5 (claude-opus-5-5)
  • Reasoning effort: low

The agent found the cause, wrote the change and ran the builds above. It is opened on behalf of @kvnloo.

Checklist

  • I have performed a self-review of my own code
  • I have run clang-format (version 18) on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Summary by CodeRabbit

  • Tests
    • Updated the empty-particle-bank test to use the expected bank index for a single rank with no particles.
    • The test continues to verify that an MCPL file is created.

The "stat:sum handles empty particle bank" section of test_mcpl_stat_sum
passed bank_index = {0}. write_mcpl_source_bank_internal() expects
n_procs + 1 cumulative offsets and reads bank_index[rank + 1], so the
test read past the end of a one-element vector. Plain builds happen to
pass; with bounds-checked standard libraries the read traps (SIGILL with
hardened libc++ as reported, SIGABRT with -D_GLIBCXX_ASSERTIONS).

Use {0, 0}, the offsets for one rank holding no particles.

Fixes openmc-dev#4054
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The empty-particle-bank test now uses bank_index = {0, 0} for one rank. It documents that bank_index contains n_procs + 1 cumulative offsets. The test still writes an MCPL file and checks that the file was created.

Changes: Empty-bank test

Layer / File(s) Summary
Set empty-bank offsets
tests/cpp_unit_tests/test_mcpl_stat_sum.cpp
The test documents the required cumulative offset length and sets bank_index to {0, 0} for one rank with no particles. It continues to check that an MCPL file is created.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other · Severity of issue fixed: Low

Suggested reviewers: bpolania, paulromano

Merge Risk: Minimal · up to 41208

This corrects an out-of-bounds read in a unit test so it no longer fails under hardened standard-library builds. Production code is unchanged, and the merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: an out-of-bounds bank_index read in the MCPL empty-bank unit test is fixed. The raw summary confirms the test input changed from {0} to {0, 0}. The title is 62 charact…
Description check Passed The description covers the change, the root cause (test passed a one-element offset vector where n_procs + 1 entries are required), the reproduction table across GCC and clang builds, and the linked i…
Linked Issues check Passed Issue #4054 reports that test_mcpl_stat_sum aborts with SIGILL at tests/cpp_unit_tests/test_mcpl_stat_sum.cpp:89, in the 'stat:sum handles empty particle bank' section. The reviewed head file sets ban…
Out of Scope Changes check Passed The raw summary and PR description identify one changed file, tests/cpp_unit_tests/test_mcpl_stat_sum.cpp, with +3/-2 lines. The head file change is limited to the empty-bank section: it changes the b…
Full details: Title check

Explanation

The title names the main change: an out-of-bounds bank_index read in the MCPL empty-bank unit test is fixed. The raw summary confirms the test input changed from {0} to {0, 0}. The title is 62 characters, within a typical length, and specific enough for a teammate scanning history.

Full details: Description check

Explanation

The description covers the change, the root cause (test passed a one-element offset vector where n_procs + 1 entries are required), the reproduction table across GCC and clang builds, and the linked issue (Fixes #4054). The AI Assistance section is filled in with harness, model, and reasoning effort. The Checklist is mostly ticked, but the Python style guideline and documentation items are unchecked. Those items are marked 'if applicable' and the change is test-only, so they are non-critical. The template's HTML comment block at the top was carried over, which is harmless. The description is complete enough to pass.

Full details: Linked Issues check

Explanation

Issue #4054 reports that test_mcpl_stat_sum aborts with SIGILL at tests/cpp_unit_tests/test_mcpl_stat_sum.cpp:89, in the 'stat:sum handles empty particle bank' section. The reviewed head file sets bank_index = {0, 0} in that section (previously {0}). src/mcpl_interface.cpp, write_mcpl_source_bank_internal(), loops over rank_idx < mpi::n_procs and reads bank_index_all_ranks[rank_idx + 1]. For one rank, this read requires two entries, so the one-element input was an out-of-bounds read. The change removes that read. The PR reports, from local builds, that the test passes with GCC 13 under -D_GLIBCXX_ASSERTIONS and with clang 18 and hardened libc++ (the failing configuration in the report), and that reverting the change restores the failure. The author did not run FreeBSD, and the full CI matrix was pending. These reports are author evidence and were not re-run in this review. The issue sets no other coding acceptance criteria. Pending: no further coding requirement is unmet.

Full details: Out of Scope Changes check

Explanation

The raw summary and PR description identify one changed file, tests/cpp_unit_tests/test_mcpl_stat_sum.cpp, with +3/-2 lines. The head file change is limited to the empty-bank section: it changes the bank_index input to {0, 0} and adds a comment explaining the n_procs + 1 offset convention. Both are directly tied to #4054. The whole-PR diff tool was unavailable (changed blobs missing from the checkout), so the file list relies on the supplied summary. Within that limit, no unrelated changes were found.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6e60a00c-ec7f-4a82-8526-d67805997f93
Commits

Reviewing files that changed from the base of the PR and between 5d63501 and 41208a0.

Files selected for processing: 1

  • tests/cpp_unit_tests/test_mcpl_stat_sum.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The test test_mcpl_stat_sum fails

1 participant